package com.tea.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tea.Model.User;
import com.tea.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户服务类
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {
    
    @Resource
    private UserMapper userMapper;
    
    /**
     * 验证给定的openId是否在允许的列表中
     * @param openId 微信小程序openId
     * @return 是否有效
     */
    public boolean isValidOpenId(String openId) {
        if (openId == null || openId.trim().isEmpty()) {
            return false;
        }
        return userMapper.countByOpenId(openId) > 0;
    }
    
    /**
     * 根据openId获取用户信息
     * @param openId 微信小程序openId
     * @return 用户信息
     */
    public User getUserByOpenId(String openId) {
        if (openId == null || openId.trim().isEmpty()) {
            return null;
        }
        return userMapper.selectByOpenId(openId);
    }
}
